package org.jeecg.modules.friends.service.impl;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
 * @author
 * Created on 2023-03-06
 */
@Slf4j
@Component
public class LCD implements BeanFactoryPostProcessor, ApplicationContextAware {

    private static ConfigurableListableBeanFactory beanFactory;
    /**
     * Spring应用上下文环境
     */
    private static ApplicationContext applicationContext;

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
            throws BeansException {
        LCD.beanFactory = beanFactory;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        LCD.applicationContext = applicationContext;
    }

    public static String getContentDefault(Integer type, String defaultStr) {
        return beanFactory.getBean(LocalCacheDictionary.class)
                .getContentDefault(type, defaultStr);
    }

    public static String getContentDefaultNoCache(Integer type, String defaultStr) {
        return beanFactory.getBean(LocalCacheDictionary.class)
                .getContentDefault(type, defaultStr);
    }
}
